import { getUserInfo } from '@/api/info'
import { getToken, setToken, removeToken } from '@/utils/auth'

const state = {
  token: getToken(),
  name: '',
  sex: '',
  age: '',
  mobile: '',
  time: '',
  roles: '',
  integral: ''
}
const mutations = {
  SET_TOKEN: (state, token) => {
    state.token = token
  }
}

const actions = {
  getUserInfo({ commit, state }) {
    return new Promise((resolve, reject) => {
      getUserInfo(state.token).then(response => {
        const { data } = response
        commit('SET_TOKEN', data.token)
        setToken(data.token)
        resolve()
      }).catch(error => {
        rejrct(error)
      })
    })
  }
}
export default {
  namespaced: true,
  actions
}
